<%@ page language="java" import="weaver.conn.RecordSet" pageEncoding="UTF-8" %>
<%@ page import="weaver.general.Util" %>
<%--获取流水号--%>
<%
    RecordSet rs = new RecordSet();
    String sql = "select a.requestid,a.xm,a.jbrq,a.jbjsrq,b.fromdatedb,b.todatedb,a.jbsc,b.duration_min from \n" +
            "(select t.requestid,t1.xm,t1.jbxs*60 as jbsc,t1.jbrq,t1.jbjsrq from formtable_main_105 t left join formtable_main_105_dt1 t1 on t.id=t1.mainid)a,\n" +
            "( select requestid,resourceid,fromdatedb,todatedb,durationrule,sum(cast(duration_min as NUMERIC)) duration_min  \n" +
            "from kq_flow_overtime where computingmode=1  \n" +
            "group by requestid,resourceid,fromdatedb,todatedb,durationrule )b\n" +
            "where a.requestId=b.requestid and a.xm=b.resourceid and a.jbrq=b.fromdatedb and a.jbjsrq=b.todatedb\n" +
            "and a.jbrq>='2022-05-01' and a.jbrq<='2022-05-30'\n" +
            "and a.jbjsrq>='2022-05-01' and a.jbjsrq<='2022-05-30'";
    rs.executeQuery(sql);
    int counts = rs.getCounts();
    out.print( "查询总数："+counts+"<br/>");
    while (rs.next()){
        String requestid = Util.null2String(rs.getString( "requestid" ));
        String xm = Util.null2String(rs.getString( "xm" ));
        String jbrq = Util.null2String(rs.getString( "jbrq" ));
        String jbjsrq = Util.null2String(rs.getString( "jbjsrq" ));
        int duration_min = Util.getIntValue(rs.getString( "duration_min" ));
        int jbsc = Util.getIntValue(rs.getString( "jbsc" ));
        out.print( "requestid="+requestid+",xm="+xm+",jbrq="+jbrq+",jbjsrq="+jbjsrq+",duration_min="+duration_min+",jbsc="+jbsc+"<br/>");

        if(duration_min < jbsc ){
            int newmin = jbsc-duration_min;
            String update_sql = "update kq_flow_overtime set duration_min=duration_min+" +newmin+
                    "where id=(select min(id) from kq_flow_overtime " +
                    "where requestid=? and resourceid=? and fromdatedb=? and todatedb=?)";
            boolean flag = rs.executeUpdate( update_sql,new Object[]{requestid,xm,jbrq,jbjsrq} );
            out.print( "数据更新状态="+flag+"<br/>" );
        }
        if(duration_min > jbsc ){
            int newmin = duration_min-jbsc;
            String update_sql = "update kq_flow_overtime set duration_min=duration_min-" +newmin+
                    "where id=(select min(id) from kq_flow_overtime " +
                    "where requestid=? and resourceid=? and fromdatedb=? and todatedb=?)";
            boolean flag = rs.executeUpdate( update_sql,new Object[]{requestid,xm,jbrq,jbjsrq} );
            out.print( "数据更新状态="+flag+"<br/>" );
        }
    }
%>
